package com.stary.beetlsql.generator.config;

import org.beetl.sql.core.NameConversion;
import org.beetl.sql.core.UnderlinedNameConversion;

import com.stary.beetlsql.generator.config.rules.IDType;
import com.stary.beetlsql.generator.util.StringUtils;

/**
 * <p>策略配置</p>
 * @author stary {@link stary1993@qq.com}
 * @since 2019-8-1
 */
public class StrategyConfig {

	/**
	 * 命名策略
	 */
	private NameConversion nc;

	/**
	 * ID类型,默认序列
	 */
	private IDType idType = IDType.SeqID;

	/**
	 * 表前缀 去掉生成实体名的前缀
	 */
	private String[] tablePrefix;

	/**
	 * 自定义继承的Entity类全称，带包名
	 */
	private String superEntityClass;
	
	/**
	 * mapper 后缀 默认Mapper
	 */
	private String mapperSuffix = Constants.MAPPER;
	
	/**
	 * service 后缀 默认Service
	 */
	private String serviceSuffix = Constants.SERVICE;
	
	/**
	 * serviceImpl 后缀 默认ServiceImpl
	 */
	private String serviceImplSuffix = Constants.SERVICE_IMPL;
	
	/**
	 * controller后缀 默认Controller
	 */
	private String controllerSuffix = Constants.CONTROLLER;
	
	/**
	 * 需要包含的表名（与exclude二选一配置）
	 */
	private String[] include = null;

	/**
	 * 需要排除的表名
	 */
	private String[] exclude = null;

	/**
	 * 【实体】是否为lombok模型（默认 false）<br>
	 * <a href="https://projectlombok.org/">document</a>
	 */
	private boolean entityLombokModel = false;

	/**
	 * 是否强制带上序列注解@SeqID<br>
	 * 相关的设置只有oracle才能生效，默认为true 
	 */
	private boolean enableTableSeqIDAnnotation = true;

	/**
	 * 自定义设置@SeqID name 前缀 + 表名，如 ：name = "SEQ_USER"
	 */
	private String tableTableSeqIDNamePrefix = null;

	/**
	 * 自定义设置@SeqID name 表名+后缀，默认_SEQ  如 ：name = "USER_SEQ"
	 */
	private String tableTableSeqIDNameSuffix="_SEQ";

	/**
	 * 表别名
	 */
	private String alias = "t";

	/**
	 * 是否生成service
	 */
	private boolean genService = true;

	/**
	 * 生成 <code>@RestController</code> 控制器
	 * <pre>
	 *      <code>@Controller</code> -> <code>@RestController</code>
	 * </pre>
	 */
	private boolean restControllerStyle = false;

	/**
	 * 自定义继承的Controller类全称，带包名
	 */
	private String superControllerClass;
	
	/**
	 *  double 类型采用BigDecimal
	 */
	private boolean preferBigDecimal = false;
	/**
	 * 采用java.util.Date
	 */
	private boolean preferDate = true;
	
	public NameConversion getNc() {
		if (nc == null) {
			nc = new UnderlinedNameConversion();
		}
		return nc;
	}

	public void setNc(NameConversion nc) {
		this.nc = nc;
	}

	public IDType getIdType() {
		return idType;
	}

	public StrategyConfig setIdType(IDType idType) {
		this.idType = idType;
		return this;
	}

	public String[] getTablePrefix() {
		return tablePrefix;
	}

	public StrategyConfig setTablePrefix(String... tablePrefix) {
		this.tablePrefix = tablePrefix;
		return this;
	}

	public String getSuperEntityClass() {
		return superEntityClass;
	}

	public StrategyConfig setSuperEntityClass(String superEntityClass) {
		this.superEntityClass = superEntityClass;
		return this;
	}


	public String getMapperSuffix() {
		if (StringUtils.isEmpty(mapperSuffix)) {
			mapperSuffix = Constants.MAPPER;
		}
		return mapperSuffix;
	}

	public StrategyConfig setMapperSuffix(String mapperSuffix) {
		this.mapperSuffix = mapperSuffix;
		return this;

	}

	public String getServiceSuffix() {
		if (StringUtils.isEmpty(serviceSuffix)) {
			serviceSuffix = Constants.SERVICE;
		}
		return serviceSuffix;
	}

	public StrategyConfig setServiceSuffix(String serviceSuffix) {
		this.serviceSuffix = serviceSuffix;
		return this;
	}

	public String getServiceImplSuffix() {
		if (StringUtils.isEmpty(serviceImplSuffix)) {
			serviceImplSuffix = Constants.SERVICE_IMPL;
		}
		return serviceImplSuffix;
	}

	public StrategyConfig setServiceImplSuffix(String serviceImplSuffix) {
		this.serviceImplSuffix = serviceImplSuffix;
		return this;
	}

	public String getControllerSuffix() {
		if (StringUtils.isEmpty(controllerSuffix)) {
			controllerSuffix = Constants.CONTROLLER;
		}
		return controllerSuffix;
	}

	public StrategyConfig setControllerSuffix(String controllerSuffix) {
		this.controllerSuffix = controllerSuffix;
		return this;
	}

	public String[] getInclude() {
		return include;
	}

	public StrategyConfig setInclude(String... include) {
		this.include = include;
		return this;
	}

	public String[] getExclude() {
		return exclude;
	}

	public StrategyConfig setExclude(String... exclude) {
		this.exclude = exclude;
		return this;
	}

	public boolean isEntityLombokModel() {
		return entityLombokModel;
	}

	public StrategyConfig setEntityLombokModel(boolean entityLombokModel) {
		this.entityLombokModel = entityLombokModel;
		return this;
	}

	public boolean isEnableTableSeqIDAnnotation() {
		return enableTableSeqIDAnnotation;
	}

	public StrategyConfig setEnableTableSeqIDAnnotation(boolean enableTableSeqIDAnnotation) {
		this.enableTableSeqIDAnnotation = enableTableSeqIDAnnotation;
		return this;
	}

	public String getTableTableSeqIDNamePrefix() {
		if (!isEnableTableSeqIDAnnotation()) {
			tableTableSeqIDNamePrefix = null;
		}
		return tableTableSeqIDNamePrefix;
	}

	public StrategyConfig setTableTableSeqIDNamePrefix(String tableTableSeqIDNamePrefix) {
		this.tableTableSeqIDNamePrefix = tableTableSeqIDNamePrefix;
		return this;
	}

	public String getTableTableSeqIDNameSuffix() {
		if (!isEnableTableSeqIDAnnotation()) {
			tableTableSeqIDNameSuffix = null;
		}
		return tableTableSeqIDNameSuffix;
	}

	public StrategyConfig setTableTableSeqIDNameSuffix(String tableTableSeqIDNameSuffix) {
		this.tableTableSeqIDNameSuffix = tableTableSeqIDNameSuffix;
		return this;
	}

	public String getAlias() {
		if (StringUtils.isEmpty(alias)) {
			alias = "t";
		}
		return alias;
	}

	public StrategyConfig setAlias(String alias) {
		this.alias = alias;
		return this;
	}

	public boolean isGenService() {
		return genService;
	}

	public StrategyConfig setGenService(boolean genService) {
		this.genService = genService;
		return this;
	}

	public boolean isRestControllerStyle() {
		return restControllerStyle;
	}

	public StrategyConfig setRestControllerStyle(boolean restControllerStyle) {
		this.restControllerStyle = restControllerStyle;
		return this;
	}

	public String getSuperControllerClass() {
		return superControllerClass;
	}

	public StrategyConfig setSuperControllerClass(String superControllerClass) {
		this.superControllerClass = superControllerClass;
		return this;
	}

	public boolean isPreferBigDecimal() {
		return preferBigDecimal;
	}

	public StrategyConfig setPreferBigDecimal(boolean preferBigDecimal) {
		this.preferBigDecimal = preferBigDecimal;
		return this;
	}

	public boolean isPreferDate() {
		return preferDate;
	}

	public StrategyConfig setPreferDate(boolean preferDate) {
		this.preferDate = preferDate;
		return this;
	}

}